TEMPORALS

Toronto Shelters

Area Facet

Photo by Brxxto on Unsplash

Photo by Brxxto on Unsplash

Everyone, rich or poor, deserves a shelter for the soul…
— Samuel


Ingest

date, shelter, sector, occupancy, and capacity

# Load csv data file
df <- read.csv("archetypes/toronto-shelters/toronto-shelters.csv", header = TRUE, stringsAsFactors = FALSE, encoding = "UTF-8")
df

Wrangle

convert dates, filter, and summarize

occupancy_rate_data <- df %>% 
  mutate(day = wday(occupancy_date, label = TRUE),
         yday = yday(occupancy_date),
         week = week(occupancy_date),
         month = month(occupancy_date, label = TRUE),
         year = year(occupancy_date)) %>% 
  filter(shelter_city == "Toronto") %>% 
  group_by(sector, year, yday) %>% 
  summarize(avg_rate = mean(occupancy/capacity,na.rm = TRUE)) %>% 
  arrange(sector, year, yday) %>% 
  group_by(sector) %>% 
  mutate(idx = row_number(),
         avg_rate = replace(avg_rate, is.infinite(avg_rate), 1))

occupancy_rate_data

Plot

facet by state

theme_opts <- theme(
    text = element_text(family = "inconsolata", size = 10), 
    plot.title = element_text(color = "black", size = 16, face = "bold"),
    plot.subtitle = element_text(color = "black", size = 12),
    plot.caption = element_text(color = "#555555", size = 10),
    panel.border = element_blank(),
    panel.background = element_blank(),
    legend.position='none',
    panel.spacing.x = unit(1, "lines"),
    panel.spacing.y = unit(1, "lines"),
    panel.grid.minor = element_blank(),
    strip.text = element_text(size = 8.5, face = "bold"),
    strip.background = element_blank()
  )

# Plot
v1 <- ggplot(occupancy_rate_data, aes(idx, avg_rate)) +
  # geom_area(fill = "#E08551", alpha = 0.4) +
  # geom_rect(aes(xmin = idx, xmax = idx+1, ymin = 0, ymax = avg_rate), fill = "blue", alpha = 0.4) +
  geom_segment(aes(x=idx,xend=idx,y=0,yend=avg_rate,color=avg_rate)) +
  scale_color_gradient(low = "yellow", high = "#E78D37") +
  geom_hline(aes(yintercept = 1.0), size = 0.5, color = "red") +
  facet_wrap( ~ sector, scales = "fixed", nrow = 1) +
  scale_x_continuous(breaks = seq(2017, 2020, by = 1), labels = c("2017", "'18", "'19", "'20")) +
  scale_y_continuous(breaks = seq(0, max(occupancy_rate_data$avg_rate) + 0.1, by = 0.1), labels = scales::percent_format(accuracy = 1) ) +
  labs(title = "Since 2017 Toronto Shelters Have Been Operating Near Or Over Capacity",
       subtitle = "occupancy rate by sector",
       caption = "Source: open.toronto.ca via {opendatatoronto}",
       x = NULL,
       y = "Capacity") +
  theme_bw() +
  theme_opts

girafe(ggobj = v1, width_svg = 1080/72, height_svg = 720/144,
       options = list(opts_sizing(rescale = TRUE, width = 0.75))
)

References

citations for narrative and data sources